
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 04/07/2014 15:17:03
-- Generated from EDMX file: C:\Users\Martin\Desktop\JobbJakt\JobbJakt\JobbJakt\JobbJakt\JJModel.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [JobbJakt];
GO
IF SCHEMA_ID(N'dbo') IS NULL EXECUTE(N'CREATE SCHEMA [dbo]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------


-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------


-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'UsersSet'
CREATE TABLE [dbo].[UsersSet] (
    [UserName] nvarchar(20)  NOT NULL,
    [SocialSecurityNumber] nvarchar(11)  NOT NULL,
    [Password] nvarchar(20)  NOT NULL,
    [Authorization] int  NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [Address] nvarchar(max)  NOT NULL,
    [ZipCode] nvarchar(6)  NOT NULL,
    [City] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Interest] nvarchar(max)  NULL,
    [Attributes] nvarchar(max)  NOT NULL,
    [Photo] nvarchar(max)  NULL,
    [RegistrationDate] datetime  NOT NULL,
    [Active] bit  NOT NULL,
    [DriversLicense] bit  NOT NULL
);
GO

-- Creating table 'LanguageSet'
CREATE TABLE [dbo].[LanguageSet] (
    [LanguageID] int IDENTITY(1,1) NOT NULL,
    [LanguageName] nvarchar(max)  NOT NULL,
    [SkillLevel] int  NOT NULL,
    [UserName] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'MeritsSet'
CREATE TABLE [dbo].[MeritsSet] (
    [MeritID] int IDENTITY(1,1) NOT NULL,
    [Merit] nvarchar(max)  NOT NULL,
    [SkillLevel] int  NOT NULL,
    [UserName] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'JobExperienceSet'
CREATE TABLE [dbo].[JobExperienceSet] (
    [JobExperienceID] int IDENTITY(1,1) NOT NULL,
    [StartDate] datetime  NOT NULL,
    [EndDate] datetime  NULL,
    [Position] nvarchar(max)  NOT NULL,
    [Employer] nvarchar(max)  NOT NULL,
    [Desciption] nvarchar(max)  NOT NULL,
    [TypeOfEmployment] int  NOT NULL,
    [UserName] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'EducationSet'
CREATE TABLE [dbo].[EducationSet] (
    [EducationID] int IDENTITY(1,1) NOT NULL,
    [StartDate] nvarchar(max)  NOT NULL,
    [EndDate] datetime  NULL,
    [EducationLevel] int  NOT NULL,
    [Name] nvarchar(max)  NOT NULL,
    [Examination] bit  NOT NULL,
    [UserName] nvarchar(20)  NOT NULL
);
GO

-- Creating table 'AdvertisementSet'
CREATE TABLE [dbo].[AdvertisementSet] (
    [AdvertisementID] int IDENTITY(1,1) NOT NULL,
    [RegistrationDate] datetime  NOT NULL,
    [Active] bit  NOT NULL,
    [Title] nvarchar(max)  NOT NULL,
    [Position] nvarchar(max)  NOT NULL,
    [Description] nvarchar(max)  NOT NULL,
    [ExpirationDate] datetime  NOT NULL,
    [Qualifications] nvarchar(max)  NOT NULL,
    [Category] nvarchar(max)  NOT NULL,
    [Salary] int  NULL,
    [TypeOfEmployment] int  NOT NULL,
    [CompanyContactID] int  NOT NULL
);
GO

-- Creating table 'CompanyContactSet'
CREATE TABLE [dbo].[CompanyContactSet] (
    [CompanyContactID] int IDENTITY(1,1) NOT NULL,
    [CompanyName] nvarchar(max)  NOT NULL,
    [FirstName] nvarchar(max)  NOT NULL,
    [LastName] nvarchar(max)  NOT NULL,
    [Position] nvarchar(max)  NOT NULL,
    [Email] nvarchar(max)  NOT NULL,
    [Phone] nvarchar(max)  NOT NULL,
    [City] nvarchar(max)  NOT NULL
);
GO

-- Creating table 'ErrorTableSet'
CREATE TABLE [dbo].[ErrorTableSet] (
    [ErrorID] int IDENTITY(1,1) NOT NULL,
    [Type] nvarchar(max)  NOT NULL,
    [Message] nvarchar(max)  NOT NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [UserName] in table 'UsersSet'
ALTER TABLE [dbo].[UsersSet]
ADD CONSTRAINT [PK_UsersSet]
    PRIMARY KEY CLUSTERED ([UserName] ASC);
GO

-- Creating primary key on [LanguageID] in table 'LanguageSet'
ALTER TABLE [dbo].[LanguageSet]
ADD CONSTRAINT [PK_LanguageSet]
    PRIMARY KEY CLUSTERED ([LanguageID] ASC);
GO

-- Creating primary key on [MeritID] in table 'MeritsSet'
ALTER TABLE [dbo].[MeritsSet]
ADD CONSTRAINT [PK_MeritsSet]
    PRIMARY KEY CLUSTERED ([MeritID] ASC);
GO

-- Creating primary key on [JobExperienceID] in table 'JobExperienceSet'
ALTER TABLE [dbo].[JobExperienceSet]
ADD CONSTRAINT [PK_JobExperienceSet]
    PRIMARY KEY CLUSTERED ([JobExperienceID] ASC);
GO

-- Creating primary key on [EducationID] in table 'EducationSet'
ALTER TABLE [dbo].[EducationSet]
ADD CONSTRAINT [PK_EducationSet]
    PRIMARY KEY CLUSTERED ([EducationID] ASC);
GO

-- Creating primary key on [AdvertisementID] in table 'AdvertisementSet'
ALTER TABLE [dbo].[AdvertisementSet]
ADD CONSTRAINT [PK_AdvertisementSet]
    PRIMARY KEY CLUSTERED ([AdvertisementID] ASC);
GO

-- Creating primary key on [CompanyContactID] in table 'CompanyContactSet'
ALTER TABLE [dbo].[CompanyContactSet]
ADD CONSTRAINT [PK_CompanyContactSet]
    PRIMARY KEY CLUSTERED ([CompanyContactID] ASC);
GO

-- Creating primary key on [ErrorID] in table 'ErrorTableSet'
ALTER TABLE [dbo].[ErrorTableSet]
ADD CONSTRAINT [PK_ErrorTableSet]
    PRIMARY KEY CLUSTERED ([ErrorID] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [UserName] in table 'LanguageSet'
ALTER TABLE [dbo].[LanguageSet]
ADD CONSTRAINT [FK_UsersLanguage]
    FOREIGN KEY ([UserName])
    REFERENCES [dbo].[UsersSet]
        ([UserName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsersLanguage'
CREATE INDEX [IX_FK_UsersLanguage]
ON [dbo].[LanguageSet]
    ([UserName]);
GO

-- Creating foreign key on [UserName] in table 'EducationSet'
ALTER TABLE [dbo].[EducationSet]
ADD CONSTRAINT [FK_UsersEducation]
    FOREIGN KEY ([UserName])
    REFERENCES [dbo].[UsersSet]
        ([UserName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsersEducation'
CREATE INDEX [IX_FK_UsersEducation]
ON [dbo].[EducationSet]
    ([UserName]);
GO

-- Creating foreign key on [UserName] in table 'JobExperienceSet'
ALTER TABLE [dbo].[JobExperienceSet]
ADD CONSTRAINT [FK_UsersJobExperience]
    FOREIGN KEY ([UserName])
    REFERENCES [dbo].[UsersSet]
        ([UserName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsersJobExperience'
CREATE INDEX [IX_FK_UsersJobExperience]
ON [dbo].[JobExperienceSet]
    ([UserName]);
GO

-- Creating foreign key on [UserName] in table 'MeritsSet'
ALTER TABLE [dbo].[MeritsSet]
ADD CONSTRAINT [FK_UsersMerits]
    FOREIGN KEY ([UserName])
    REFERENCES [dbo].[UsersSet]
        ([UserName])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_UsersMerits'
CREATE INDEX [IX_FK_UsersMerits]
ON [dbo].[MeritsSet]
    ([UserName]);
GO

-- Creating foreign key on [CompanyContactID] in table 'AdvertisementSet'
ALTER TABLE [dbo].[AdvertisementSet]
ADD CONSTRAINT [FK_AdvertisementCompanyContact]
    FOREIGN KEY ([CompanyContactID])
    REFERENCES [dbo].[CompanyContactSet]
        ([CompanyContactID])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_AdvertisementCompanyContact'
CREATE INDEX [IX_FK_AdvertisementCompanyContact]
ON [dbo].[AdvertisementSet]
    ([CompanyContactID]);
GO


-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------